import { vLoading } from "./directive";
import type { IBinding } from "./types";

let close: { (): void } | undefined;

export function loading(value: boolean = false) {
  if (!close) {
    const destroySelf = vLoading(document.body, { value, modifiers: { body: true } } as IBinding)
    close = () => {
      destroySelf?.()
      close = undefined
    }
  }

  return {
    close
  }
}